﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Extention.ENode.Rpc.Runtime.Server
{
    public interface IServiceHostBalance
    {

        /// <summary>
        /// 获取一个Host  根据权重获取
        /// </summary>
        /// <returns>获取一个HOST</returns>
        Task<RouteBalanceModel> GetOneHost();

        /// <summary>
        /// 获取Host的负载均衡
        /// </summary>
        /// <returns>Host的负载均衡集合</returns>
        Task<IEnumerable<RouteBalanceModel>> GetHostBalance();

        /// <summary>
        /// 设置Host的负载
        /// </summary>
        /// <param name="routes">服务路由集合</param>
        /// <returns>一个任务</returns>
        Task SetHostsBalance(RouteBalanceModel route);

        /// <summary>
        /// 清空所有的Host负载
        /// </summary>
        /// <returns>一个任务</returns>
        Task ClearAsync();


        /// <summary>
        /// 移除一个HOST 如果只剩最后一个，那么不会移除
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        Task Remove(RouteBalanceModel route);

    }

    public class RouteBalanceModel
    {

        /// <summary>
        /// 权重等级
        /// </summary>
        public int Level { get; set; }


        /// <summary>
        /// 平衡的KEY
        /// </summary>
        public string BalanceKey { get; set; }


    }
}
